package com.yao.component.cityselector;

import com.amap.api.location.AMapLocation;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;

public class Util {

	/**
	 *  开始定位
	 */
	public final static int MSG_LOCATION_START = 0;
	/**
	 * 定位完成
	 */
	public final static int MSG_LOCATION_FINISH = 1;

	/**
	 * 根据定位结果返回定位信息的字符串
	 * @return
	 */
	public synchronized static String getLocationStr(AMapLocation location){
		if(null == location){
			return null;
		}
		StringBuffer sb = new StringBuffer();
		//errCode等于0代表定位成功，其他的为定位失败，具体的可以参照官网定位错误码说明
		if(location.getErrorCode() == 0){
			if (location.getProvider().equalsIgnoreCase(android.location.LocationManager.GPS_PROVIDER)) {
			} else {
				sb.append(location.getCity());
			}
		} else {
			//定位失败
			sb.append("定位失败");
		}
		return sb.toString();
	}

	/**
	 * 获得当前时间
	 *
	 * @return
	 */
	public static String getNowDate() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(date);
	}


	/**
	 * 判断是否是手机号码11位数字
	 *
	 * @param str
	 * @return
	 */
	public static boolean isPhoneNum(String str) {
		Pattern pattern = Pattern.compile("^\\d{11}$");
		return pattern.matcher(str).matches();
	}

	public static  boolean isEmpty(String s){
		if("".equals(s)||s==null){
			return true;
		}else{
			return false;
		}

	}
}
